package com.raycloud.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.raycloud.dao.UserDao;
import com.raycloud.dao.common.BaseDao;
import com.raycloud.domain.User;

public class UserDaoImpl extends BaseDao implements UserDao{

	public void insertUser(User user) {
		getSqlMapClientTemplate().insert("user.insertUser", user);
	}

	public User getUser(String email, String password) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("email", email);
		codition.put("password", password);
		return (User) getSqlMapClientTemplate().queryForObject("user.getUserByEmailAndPassword", codition);
	}

	public User getUserById(long id) {
		return (User) getSqlMapClientTemplate().queryForObject("user.getUserById", id);
	}

	@SuppressWarnings("unchecked")
	public List<User> queryTopNUsers(int limitCount, long id) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("limitCount", limitCount);
		codition.put("id", id);
		return getSqlMapClientTemplate().queryForList("user.queryTopNUsers", codition);
	}

	public void updateFieldCount(long id, int offset, String type) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("id", id);
		codition.put("offset", offset);
		codition.put("type", type);
		getSqlMapClientTemplate().update("user.updateFieldCount", codition);
	}

}
